<template>
	<div class="ele-body">
		<div class="ele-bg-white padding-15">
			<a-space size="middle" class="analysis-tabs-extra">
				<a-radio-group v-model:value="checked" @change="toggleChange">
					<a-radio-button value="1">首饰调拨</a-radio-button>
					<a-radio-button value="2">饰品调拨</a-radio-button>
					<a-radio-button value="3">旧货调拨</a-radio-button>
					<a-radio-button value="4">礼品调拨</a-radio-button>
				</a-radio-group>
			</a-space>
			<div class="padding-15">
				<div v-for="(item, index) in list" :key="`id${index}`">
					<div class="padding-y-10 margin-bottom-15 solid-bottom fs-16 fw-bolder">{{ item.name }}</div>
					<a-row :gutter="15" class="margin-y-15" v-for="(m, mindex) in item.list" :key="`ids${mindex}`">
						<a-col :md="3" :sm="6" :xs="6">
							<div>{{ m.name }}：</div>
						</a-col>
						<a-col :md="21" :sm="18" :xs="18">
							<!-- <a-checkbox-group :name="`checkbox${mindex}`" v-model:value="m.value" @change="change($event, index, mindex)" v-if="index == list.length - 1">
								<a-checkbox value="1"><span class="text_wrap">公司审核</span></a-checkbox>
								<a-checkbox value="2"><span class="text_wrap">门店审核</span></a-checkbox>
							</a-checkbox-group>
							<a-radio-group :name="`radio${mindex}`" v-model:value="m.value" @change="change($event, index, mindex)" v-else>
								<template v-if="mindex == 0">
									<a-radio value="1"><span class="text_wrap">允许</span></a-radio>
									<a-radio value="2"><span class="text_wrap">不允许</span></a-radio>
								</template>
								<template v-else>
									<a-radio value="1"><span class="text_wrap">手动收货</span></a-radio>
									<a-radio value="2"><span class="text_wrap">自动收货</span></a-radio>
								</template>
							</a-radio-group> -->
							<a-radio-group :name="`radio${mindex}`" v-model:value="m.value" @change="change($event, index, mindex)">
								<template v-if="mindex == 0">
									<a-radio value="1"><span class="text_wrap">允许</span></a-radio>
									<a-radio value="2"><span class="text_wrap">不允许</span></a-radio>
								</template>
								<template v-else>
									<a-radio value="1"><span class="text_wrap">手动收货</span></a-radio>
									<a-radio value="2"><span class="text_wrap">自动收货</span></a-radio>
								</template>
							</a-radio-group>
						</a-col>
					</a-row>
				</div>

				<!-- <a-space class="margin-top-30"><a-button type="primary">保存</a-button></a-space> -->
			</div>
		</div>
	</div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';
import { Form, message } from 'ant-design-vue';
import { get_list, edit_setting } from '@/api/setting/allocation_setting';

const checked = ref('1');
const list = ref([]);

onMounted(() => {
	getData();
});

const getData = () => {
	get_list({ cate: checked.value })
		.then(res => {
			list.value = res.data;
			list.value.forEach((item, index) => {
				item.list.forEach(m => {
					/* if (index == list.value.length - 1) {
						if (m.status == 3) {
							m.value = ['1', '2'];
						} else {
							m.value = [m.status.toString()];
						}
					} else {
						m.value = m.status.toString();
					} */
					m.value = m.status.toString();
				});
			});
		})
		.catch(e => {
			message.error(e);
		});
};

const toggleChange = e => {
	checked.value = e.target.value;
	getData();
};
const change = (e, index, mindex) => {
	let status = '';
	/* if (index == list.value.length - 1) {
		if (e.length < 1) {
			status = '0';
		} else if (e.length > 1) {
			status = '3';
		} else {
			status = e.join(',');
		}
	} else {
		status = e.target.value;
	} */
	status = e.target.value;
	edit_setting({ id: list.value[index].list[mindex].id, status: status })
		.then(res => {
			message.success(res.msg);
			getData();
		})
		.catch(e => {
			message.error(e.message || e);
		});
};
</script>

<style lang="less" scoped>
.text_wrap {
	display: inline-block;
	min-width: 100px;
}
</style>
